package com.chaos.auth.api.dto.userdetails;

import com.chaos.auth.api.data.TUserData;
import com.chaos.framework.model.constant.Constants;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDate;
import java.util.Collection;


@Data
public class UserUserDetails implements UserDetails {
    private Long userId;

    private String username;

    private Boolean enabled;

    private String authenticationIdentity;

    private Long tenantId;

    @ApiModelProperty(value = "头像")
    private String avatar;

    @ApiModelProperty(value = "生日")
    private LocalDate birthday;

    @ApiModelProperty(value = "性别 保密、男、女 对应0、1 、2")
    private Integer gender;

    @ApiModelProperty(value = "phone")
    private String phone;


    /**
     * 用户信息构建
     *
     * @param userData 用户参数信息
     */
    public UserUserDetails(TUserData userData) {
        this.setUserId(userData.getId());
        this.setUsername(userData.getNickname());
        this.setEnabled(userData.getStatus().equals(Constants.FALSE));
        this.setTenantId(userData.getTenantId());
        this.setAvatar(userData.getAvatar());
        this.setBirthday(userData.getBirthday());
        this.setGender(userData.getGender());
        this.setPhone(userData.getPhone());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }
}
